package com.lvmama.pangolin.timer.processor;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.lvmama.pangolin.busi.config.ConfigManager;
import com.lvmama.pangolin.busi.timer.TimerManager;
import com.lvmama.pangolin.service.PreviousDataService;
import com.lvmama.pangolin.timer.CommonJob;
import com.lvmama.pangolin.util.SpringContextUtil;


public class PreviousDataDeal  extends CommonJob 
{
	@Autowired
	private PreviousDataService service;
	
	private Logger logger = Logger.getLogger(PreviousDataDeal.class);
	
	@Override
	public void runJob(JobExecutionContext context, String parameter)
	{
		logger.info("删除前N周期数据开始...");
		if(service == null)
		{
			service = (PreviousDataService) SpringContextUtil.getBean(PreviousDataService.class);
		}
		String configParam = (String) context.getJobDetail().getJobDataMap()
				.get(TimerManager.JOB_DATAKEY);
		String limit = ConfigManager.getInstance().getParamValue(configParam, "LIMIT", "10");
		String convertLimit = ConfigManager.getInstance().getParamValue(configParam, "CONVERT_LIMIT", "20");
		String convertFlag = ConfigManager.getInstance().getParamValue(configParam, "CONVERT_FLAG", "0");
		service.deletePreviousData(Integer.valueOf(limit));
		if("1".equals(convertFlag))
		{
			service.deleteConvertPreviousData(Integer.valueOf(convertLimit));
		}
		logger.info("删除前N周期数据结束....N: " + limit + " CONVERT_LIMIT : " + convertLimit);
		
	}

}
